<template>
<div class="probability-count">
    <title-bar title="概率分段统计"></title-bar>
    <div class="tab">
        <el-radio-group v-model="type">
            <el-radio-button v-for="(item, i) in typeList" :key="i" :label="item.value">{{item.name}}</el-radio-button>
        </el-radio-group>
    </div>
    <el-table border :data="list[type]" height="400px">
        <el-table-column v-for="(item, i) in colsArray[type]" :key="i" :prop="item.key" :label="item.label" width="100px" show-overflow-tooltip>
            <template slot-scope="scope">
                <template v-if="item.key === 'groups'">{{`[${scope.row.groups}]`}}</template>
                <template v-if="i === 1 && type === 1">{{`[${scope.row.probability}]`}}</template>
                <template v-if="!['groups', 'probability'].includes(item.key)">
                    <box-line v-if="boxShadow.includes(item.key)" :item="getRate(scope.row, scope.row[item.key])"></box-line>
                    <template v-else>{{scope.row[item.key]}}</template>
                </template>
            </template>
        </el-table-column>
    </el-table>
</div>
</template>

<script>
import TitleBar from '@/components/TitleBar'
import BoxLine from './BoxLine'
import {
    mapGetters
} from 'vuex'
export default {
    components: {
        TitleBar,
        BoxLine
    },
    computed: {
        ...mapGetters({
            modelDetail: 'common/getModelDetail'
        })
    },
    data () {
        return {
            boxShadow: ['truePositiveSample', 'falsePositiveSample', 'falseNegativeSample', 'trueNegativeSample'],
            type: 0,
            typeList: [
                {
                    name: '等宽',
                    value: 0
                },
                {
                    name: '等频',
                    value: 1
                }
            ],
            list: [ [], [] ],
            colsArray: [
                [
                    {
                        key: 'groups',
                        label: '预测概率'
                    },
                    {
                        key: 'depth',
                        label: '样本占比'
                    },
                    {
                        key: 'truePositiveSample',
                        label: '真正例'
                    },
                    {
                        key: 'falsePositiveSample',
                        label: '伪正例'
                    },
                    {
                        key: 'falseNegativeSample',
                        label: '伪负例'
                    },
                    {
                        key: 'trueNegativeSample',
                        label: '真负例'
                    },
                    {
                        key: 'accuracy',
                        label: 'Accuracy'
                    },
                    {
                        key: 'precision',
                        label: 'Precision'
                    },
                    {
                        key: 'recall',
                        label: 'Recall'
                    },
                    {
                        key: 'f1',
                        label: 'F1-Score'
                    },
                    {
                        key: 'tnr',
                        label: 'TNR'
                    },
                    {
                        key: 'piecesAuc',
                        label: '本组AUC'
                    },
                    {
                        key: 'accumulatedAuc',
                        label: '累计AUC'
                    }
                ],
                [
                    {
                        key: 'groups',
                        label: '频度'
                    },
                    {
                        key: 'probability',
                        label: '预测概率'
                    },
                    {
                        key: 'truePositiveSample',
                        label: '真正例'
                    },
                    {
                        key: 'falsePositiveSample',
                        label: '伪正例'
                    },
                    {
                        key: 'falseNegativeSample',
                        label: '伪负例'
                    },
                    {
                        key: 'trueNegativeSample',
                        label: '真负例'
                    },
                    {
                        key: 'accuracy',
                        label: 'Accuracy'
                    },
                    {
                        key: 'precision',
                        label: 'Precision'
                    },
                    {
                        key: 'recall',
                        label: 'Recall'
                    },
                    {
                        key: 'f1',
                        label: 'F1-Score'
                    },
                    {
                        key: 'tnr',
                        label: '特异率'
                    },
                    {
                        key: 'piecesAuc',
                        label: '本组AUC'
                    },
                    {
                        key: 'accumulatedAuc',
                        label: '累计AUC'
                    }
                ]
            ]
        }
    },
    created () {
        this.init()
    },
    methods: {
        init () {
            const data = this.modelDetail.summary.evaSummary
            this.list = [data.pieceProbabilitySummary, data.pieceSampleSummary]
        },
        getRate (item, value) {
            let rate = value === 0 ? 0 : value / (item.truePositiveSample + item.falsePositiveSample + item.falseNegativeSample + item.trueNegativeSample)
            return { value, rate }
        }
    }
}
</script>

<style lang="less">
.probability-count {
    .tab {
        text-align: center;
        padding-bottom: 8px;
    }
    .el-radio-button__inner {
        min-width: 80px;
    }
    .el-table .cell {
        white-space: nowrap;
    }
}
</style>
